package com.qk.management.service.impl;

import cn.hutool.core.bean.BeanUtil;

import com.qk.entity.domain.business.BusinessCountDO;
import com.qk.entity.domain.clue.ClueCountDO;
import com.qk.management.aop.anno.Cacheable;
import com.qk.entity.vo.portal.PortalVO;
import com.qk.management.mapper.BusinessMapper;
import com.qk.management.mapper.ClueMapper;
import com.qk.management.service.ReportOverviewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

import static com.qk.common.constant.CacheConstants.CACHE_PORTAL_KEY_PREFIX;

/**
 * @author fantuan
 * @created 2025/10/15 14:53
 * @description
 */
@Slf4j
@Service
public class ReportOverviewServiceImpl implements ReportOverviewService {
    @Autowired
    private ClueMapper clueMapper;
    @Autowired
    private BusinessMapper businessMapper;

    @Override
    public PortalVO reportOverviewWithCache() {

        ClueCountDO clueCountDO = clueMapper.selectCountClue();
        BusinessCountDO businessCountDO = businessMapper.selectCountBusiness();
        PortalVO vo = BeanUtil.copyProperties(clueCountDO, PortalVO.class);
        BeanUtil.copyProperties(businessCountDO, vo);
        return vo;
    }
    @Cacheable(redisKeyPrefix = CACHE_PORTAL_KEY_PREFIX, redisKeyExpireTime = 24 * 60L, redisKeyExpireTimeUnit = TimeUnit.MINUTES)
    @Override
    public PortalVO getOverview() {
        ClueCountDO clueCountDO = clueMapper.selectCountClue();
        BusinessCountDO businessCountDO = businessMapper.selectCountBusiness();
        PortalVO vo = BeanUtil.copyProperties(clueCountDO, PortalVO.class);
        BeanUtil.copyProperties(businessCountDO, vo);
        return vo;
    }
}
